package com.fmsz.xmly.adapters.classify.tag;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.fmsz.xmly.R;
import com.fmsz.xmly.entitys.classify.tag.AllTagEntity;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/13.
 */

public class ClassifyAllTagAdapter extends RecyclerView.Adapter<ClassifyAllTagAdapter.ViewHolder>{

    private Context context;
    private List<AllTagEntity.AllTagListEntity> datas;

    public ClassifyAllTagAdapter(Context context) {
        this.context = context;
        datas = new ArrayList<>();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.classify_tag_item_nomal,parent,false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.title.setText(datas.get(position).getTitle());
        holder.subTitle.setText(datas.get(position).getIntro());
        holder.playsCount.setText(datas.get(position).getPlaysCounts());
        holder.duration_tv.setText(datas.get(position).getTracks());
        Picasso.with(context).load(datas.get(position).getCoverSmall()).into(holder.icon_rv);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }
    public void addAll(List<AllTagEntity.AllTagListEntity> datas){
        this.datas.addAll(datas);
        notifyDataSetChanged();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView icon_rv;
        private TextView title;
        private TextView subTitle;
        private TextView duration_tv;
        private TextView playsCount;
        public ViewHolder(View itemView) {
            super(itemView);
            initView(itemView);
        }
        private void initView(View itemView) {
            icon_rv = ((ImageView) itemView.findViewById(R.id.icon_tag_lv));
            title = ((TextView) itemView.findViewById(R.id.title_tag_normal));
            subTitle = ((TextView) itemView.findViewById(R.id.subTitle_tag_normal));
            duration_tv = ((TextView) itemView.findViewById(R.id.duration_tag_normal));
            playsCount = ((TextView) itemView.findViewById(R.id.playsCount_tag));
        }
    }
}
